import React, { Component } from 'react'
import Getnew from './components/Getnew/Getnew'
import Goodslist from './components/Goodslist/Goodslist'
import { reqgetnew,reqgetindexgoods } from '../../http/api'


export default class Home extends Component {
  constructor(){
    super()
    this.state={
      newshop:[],
      goodlist:[],
      n:0,
    }
  }

  componentDidMount(){
    /* newshop数据 */
    reqgetnew().then((res)=>{
      if(res.data.code === 200){
        let arr = res.data.list;
        this.setState({
          newshop:arr,
        })
      }
    })
    /* goodlist数据 */
    reqgetindexgoods().then((res)=>{
      if(res.data.code === 200){
        let arr = res.data.list;
        this.setState({
          goodlist:arr,
        })
      }
    })
  }

  /* 改变参数 */
  changeIndex(n){
    this.setState({
      n
    })
  }

  render() {
    let {newshop,goodlist,n} = this.state;
    console.log(n);
    console.log(goodlist);
    return (
      <div>
        <Getnew newshop={newshop}></Getnew>
        <Goodslist goodlist={goodlist} changeIndex={(n)=>this.changeIndex(n)} n={n}></Goodslist>
      </div>
    )
  }
}
